package com.springmvc.demo.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.springmvc.demo.model.RoleMenu;
import com.springmvc.demo.service.MenuService;

@Controller
public class MenuController {
	@Autowired
	MenuService menuServiceImpl;
	
	@RequestMapping("/loadMenu")
	@ResponseBody
	public JSONObject getMenu(HttpSession session) {
		String roleid =(String)session.getAttribute("roleid");
		
		if(roleid!=null) {
		System.out.println("============ roleid："+roleid);
		List<RoleMenu> list=menuServiceImpl.loadMenu(roleid);
		JSONObject rs=new JSONObject();
		JSONArray jsonArray=(JSONArray)JSONArray.toJSON(list);
		rs.put("list",jsonArray);
			return rs;
		}else {
			return null;
		}
	}
	
	@RequestMapping("/addMenu")
	@ResponseBody
	public String addMenu(RoleMenu rm) {
		return menuServiceImpl.addMenu(rm);
		
	}
	
}
